package com.xigua.nio;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannel01 {
    public static void main(String[] args) throws IOException {
        String str = "hello 尚硅谷";

        //创建一个输出流->channel
        FileOutputStream fileOutputStream = new FileOutputStream("d://file01.txt");
        //通过fileOutputStream 获取对应的FileChannel

        FileChannel channel = fileOutputStream.getChannel();
        ByteBuffer buffer = ByteBuffer.allocate(1024);

        buffer.put(str.getBytes());
        buffer.flip();
        channel.write(buffer);
        fileOutputStream.close();


    }
}
